package thread;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * sleep阻塞
 * 线程提供了一个静态方法:
 * static void sleep(long ms)
 * 该方法可以让执行该方法的线程处于阻塞状态指定毫秒，超时后线程会再次回到RUNNABLE状态
 * 再次并发
 */
public class SleepDemo {
    public static void main(String[] args) {
        /*
            System.out.println("程序开始了...");
            try {
                Thread.sleep(5000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("程序结束了...");
         */
        System.out.println("请输入倒计时数字:");
        BufferedReader br = new BufferedReader(
                new InputStreamReader(
                        System.in
                )
        );
        try {
            int time = Integer.parseInt(br.readLine());
//        Scanner sc = new Scanner(System.in);
//        int time = sc.nextInt();
        while (time != 0) {
            System.out.println(time--);
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
